﻿using Abp.Application.Services.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Commodity.Commodities.Dto
{
    public class CommodityDto: EntityDto
    {
        public string Name { get; set; }
        public int CommodityWareId { get; set; }
        public List<string> Classes { get; set; }
        public List<string> Tags { get; set; }

        public bool Shelved { get; set; }
        public bool IsRecommended { get; set; }
        public bool IsEnabledShoppingOption { get; set; }
        public bool Discountable { get; set; }
        public bool IsDiscountPerLevel { get; set; }
        public List<string> SelectedShoppingOptionParameters { get; set; }

        public double Price { get; set; }
        public int XPValue { get; set; }
        public int Inventory { get; set; }
        public int MinLimitCount { get; set; }
        public int MaxLimitCount { get; set; }
        public string Picture { get; set; }
        public List<string> Pictures { get; set; }
        public string Description { get; set; }

        public Dictionary<string, string> SpecificationParameters { get; set; }
        public Dictionary<int, double> Discounts { get; set; }

        public List<ShoppingOptionDto> ShoppingOptions { get; set; }

        public long? CreatorUserId { get; set; }

        public DateTime CreationTime { get; set; }

        public CommodityDto()
        {
            Classes = new List<string>();
            Tags = new List<string>();
            SelectedShoppingOptionParameters = new List<string>();
            Pictures = new List<string>();
            SpecificationParameters = new Dictionary<string, string>();
            Discounts = new Dictionary<int, double>();
            ShoppingOptions = new List<ShoppingOptionDto>();
        }

        public CommodityDto(Commodity commodity, List<CommodityShoppingOption> commodityShoppingOptions = null)
        {
            Id = commodity.Id;
            Name = commodity.Name;
            Classes = commodity.Classes.Items;
            Tags = commodity.Tags.Items;
            Shelved = commodity.Shelved;
            IsDiscountPerLevel = commodity.IsDiscountPerLevel;
            IsEnabledShoppingOption = commodity.IsEnabledShoppingOption;
            IsRecommended = commodity.IsRecommended;
            Discountable = commodity.Discountable;
            SelectedShoppingOptionParameters = commodity.SelectedShoppingOptionParameters.Items;
            if(commodityShoppingOptions != null)
            {
                ShoppingOptions = commodityShoppingOptions.Select(r => new ShoppingOptionDto(r)).ToList();
            }
            Discounts = commodity.Discounts;
            SpecificationParameters = commodity.SpecificationParameters;
            Price = commodity.ShoppingInfo.Price.Value;
            XPValue = commodity.ShoppingInfo.XPValue;
            CommodityWareId = commodity.CommodityWareId;
            CreationTime = commodity.CreationTime;
            CreatorUserId = commodity.CreatorUserId;
            MaxLimitCount = commodity.ShoppingInfo.MaxLimitCount;
            MinLimitCount = commodity.ShoppingInfo.MinLimitCount;
            Inventory = commodity.ShoppingInfo.Inventory;
            Picture = commodity.ShoppingInfo.Picture;
            Pictures = commodity.ShoppingInfo.Pictures.Items;
            Description = commodity.Description;
        }
    }
}
